package com.systemic.service.impl;

import com.systemic.mapper.GroupLogMapper;
import com.systemic.pojo.GroupLog;
import com.systemic.service.GroupLogService;
import com.systemic.vo.PageVo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @ClassName: GroupLogServiceImpl
 * @Description:
 * @Author:
 * @CreateTime: 2024-02-02 14:46
 * @Version:
 **/
@Service
public class GroupLogServiceImpl implements GroupLogService {

    @Resource
    private GroupLogMapper groupLogMapper;

    /**
     * 练习打卡新增
     *
     * @param groupLog
     * @return
     */
    @Override
    @Transactional
    public int clockInAdd(GroupLog groupLog) {
        int row = 0;
        groupLog.setGmtCreate(new Date());
        row = groupLogMapper.insert(groupLog)+row;
        return row;
    }

    /**
     * 练习打卡查看
     * @param pageVo
     * @return
     */
    @Override
    public List<GroupLog> clockIn(PageVo pageVo) {
        // 获取当前页数和每页显示的数据条数
        Integer pageNo = pageVo.getPageNo();
        Integer pageSize = pageVo.getPageSize();
        // 计算OFFSET值
        Integer offset = (pageNo - 1) * pageSize;
        Integer gmId = pageVo.getId();
        return groupLogMapper.selectListByGid(gmId,offset,pageSize);
    }

    /**
     * 练习打卡删除
     * @param id
     * @return
     */
    @Override
    @Transactional
    public int clockInDelete(Integer id) {
        int row = 0;
        GroupLog groupLog = new GroupLog();
        groupLog.setId(id);
        row = groupLogMapper.delete(groupLog)+row;
        return row;
    }
}
